package org.lex.tinyscript.command;

import java.util.Arrays;

import org.lex.tinyscript.TinyScriptException;

public abstract class AbstractScriptCommand implements ScriptCommand {
	protected void checkArgumentsLength(int length, String... arguments)
			throws TinyScriptException {
		if (0 == length) {
			// can't have argument
			if (null != arguments && 0 != arguments.length) {
				throw new TinyScriptException("Command [" + this.getCommand()
						+ "] takes only ZERO arguments: "
						+ Arrays.toString(arguments));
			}
		} else {
			// must have arguments
			if (null == arguments) {
				throw new TinyScriptException("Command [" + this.getCommand()
						+ "]'s arguments can't be null!");
			}
			if (length != arguments.length) {
				throw new TinyScriptException("Command [" + this.getCommand()
						+ "] must have exactly " + length
						+ " arguments, but actually got " + arguments.length
						+ " arguments" + Arrays.toString(arguments));
			}
		}
	}

	public AbstractScriptCommand clone() throws CloneNotSupportedException {
		return (AbstractScriptCommand) super.clone();
	}
}
